<?
session_start();

//exit translate('scheduled_maintenance');
include('../sessions.php');
include('../variables.php');
include('../u/functions.php');
include('../libs/global_functions.php');
//$webDIR="login";
include('variables.php');
include("session_check.php");
include('../init.php');
include_once('multi_language.php');
include_once('functions.php');

// sve: Start Xajax
include_once('xajax.php');
// sve: End Xajax

//$id = $_SESSION['id'];
$userName = $_SESSION['userName'];
// sve: patch for the W9 form
$rslDetails = list_details($_SESSION['id'], 'array');
$resellerCountry = $rslDetails[0]['country'];
unset($rslDetails);
//echo $action;
if (getenv(REQUEST_METHOD) == "GET") {
	switch($action) {
		case "mainPanel":
			$fileTemplate="mainPanel.html";
			include("main.html");
			break;
		case "changeDetails":
			$fileTemplate="changeDetails.html";
			include("main.html");
			break;
		case "changeBankDetails":
			$fileTemplate="changeBankDetails.html";
			include("main.html");
			break;
		case "editPlans":
			$fileTemplate="editPlans.html";
			include("main.html");
			break;
		case "managePlans":
			$fileTemplate="managePlans.html";
			include("main.html");
			break;
		case "sales":
			$fileTemplate="sales.html";
			include("main.html");
			break;
		case "payments":
			$fileTemplate="payments.html";
			include("main.html");
			break;
		case "payment_details":
			$fileTemplate="payment_details.html";
			include("main.html");
			break;
		case "editStyle":
			$fileTemplate="editStyle.html";
			include("main.html");
			break;
		case "editHeader":
			$fileTemplate="editHeader.html";
			include("main.html");
			break;
		case "editFooter":
			$fileTemplate="editFooter.html";
			include("main.html");
			break;
		case "editMenu":
			$fileTemplate="editMenu.html";
			include("main.html");
			break;
		case "editTemplate":
			$fileTemplate="editTemplate.html";
			include("main.html");
			break;
		case "editRemoteTemplate":
			include("../remote_functions.php");
			$fileTemplate="editRemoteTemplate.html";
			include("main.html");
			break;
		case "editRemoteFormsDomain":
			$fileTemplate="editRemoteFormsDomain.html";
			include("main.html");
			break;
		case "editRemoteFormsOrder":
			$fileTemplate="editRemoteFormsOrder.html";
			include("main.html");
			break;
		case "editDescription":
			$fileTemplate="editDescription.html";
			include("main.html");
			break;
		case "viewClients":
			$fileTemplate="clientLogin.html";
			//$fileTemplate="viewClients.html";
			include("main.html");
			break;
		case "viewSales":
			$fileTemplate="viewSales.html";
			include("main.html");
			break;
		case "client_login":
			$word=md5(uniqid(rand(),1));
			$secret_word='as4dfSD5fdsadf';
			$secret=urlencode((crypt($client.$userName.$word.$secret_word)));
			header("Location: http://www.supremeserver1.com/resellers/login/redirect_login.php?username=$client&reseller=$userName&word=$word&secret=$secret");
			break;
		case "viewAffiliates":
			$fileTemplate="viewAffiliates.html";
			include("main.html");
			break;
		case "add_domain":
			$fileTemplate="domain.html";
			include("main.html");
			break;
		case "emails":
			if(!get_reseller_domain($id)){
				$fileTemplate="emails.html";
				$errorMsg = translate('add_domain_name_first');
			}
			else $fileTemplate="emails.html";

			include("main.html");
			break;
		case "editStoreName":
			$fileTemplate="editStoreName.html";
			include("main.html");
			break;
		case "editServicePrices":
			$fileTemplate="editServicePrices.html";
			include("main.html");
			break;
		case "manageEmailNotifications":
			$fileTemplate="manageEmailNotifications.html";
			include("main.html");
			break;
		case "editMeta":
			$fileTemplate="editMeta.html";
			include("main.html");
			break;
		case "editContacts":
			$fileTemplate="editContacts.html";
			include("main.html");
			break;
		case "editAboutUs":
			$fileTemplate="editAboutUs.html";
			include("main.html");
			break;
		case "order":
			//$fileTemplate = 'order/order.html';
			$fileTemplate = 'order/order_wp.html';
			include("main.html");
			break;
		case 'order_wp':
			$fileTemplate = 'order/order_wp.html';
			include("main.html");
			break;
		case "stats":
			$fileTemplate="stats.html";
			include("main.html");
			break;
		case "redirect":
			if($url){
				header("Referer: ");
				header("Location: $url");
				exit();
			}
			break;
		case "remote_order":
			$fileTemplate="remote_order.html";
			include("main.html");
			break;
		case "remote_domain":
			$fileTemplate="remote_domain.html";
			include("main.html");
			break;
		case "remote_login":
			$fileTemplate="remote_login.html";
			include("main.html");
			break;
		case "clients_details":
			$fileTemplate="clients.html";
			include("main.html");
			break;
		case "renew":
			$fileTemplate="manualRenew.html";
			include("main.html");
			break;
		case "renewClient":
			$fileTemplate="renewClient.html";
			include("main.html");
			break;
		case "editW9Form":
			$fileTemplate="editW9Form.html";
			include("main.html");
			break;
		case "logout":
//			kill_session($sid);
			session_destroy();
			header("Location: $baseURL/");
			break;
		case "change_lang":
			if(!validate($language)) {
				$errorMsg = translate("invalid_language");
				if($url) {
					header("Location: ".$url);
				}
				else {
					if($laction) {
						$params[sid] = $sid;
						$params[action] = $laction;
						$url = "$baseURL/?".encode_params($params);
						header("Location: ".$url);
						exit();
					}
					$fileTemplate='mainPanel.html';
					include("main.html");
				}
			}
			$lang = $language;
			$_SESSION['lang'] = $language;
			//session_register_('lang',sid);
			//session_save();

			if($url) {
				header("Location: ".$url);
			}
			else {
				$fileTemplate='mainPanel.html';
				include("main.html");
			}
			break;
		case 'editApiSettings':
			$fileTemplate="editApiSettings.html";
			include("main.html");
			break;
		case "walletAccountRefill":
			#include('../rp2/global_functions.php');
			#include('../rp2/mail_functions.php');
			#include('../rp2/functions.php');
			include('wallet_db.html');
			$fileTemplate="walletAccountRefill.html";
			include("main.html");
			break;
		case "walletPaymentHistory":
			$fileTemplate="walletPaymentHistory.html";
			include("main.html");
			break;
		case "walletSettings":
			$fileTemplate="walletSettings.html";
			include("main.html");
			break;
		case "currencyExchange":
			$fileTemplate="currencyExchange.html";
			include("main.html");
			break;
		case "currencyExchangeHistory":
			$fileTemplate="currencyExchangeHistory.html";
			include("main.html");
			break;
		case "downloadApiDemo":
			$fileTemplate="downloadApiDemo.html";
			include("main.html");
			break;
		case "editClientsUpgrades":
			$fileTemplate="editClientsUpgrades.html";
			include("main.html");
			break;
		case "manualUpgrades":
	      $fileTemplate="manualUpgrades.html";
	      include("main.html");
	      break;
		case "check_domain_availability":
	      $fileTemplate="domain/check_domain_availability.html";
	      include("main.html");
	      break;
		case "register_domain":
	      $fileTemplate="domain/register_domain.html";
	      include("main.html");
	      break;
		case "changedetails":
	      $fileTemplate="domain/changedetails.html";
	      include("main.html");
	      break;
		case "domain_renew":
	      $fileTemplate="domain/domain_renew.html";
	      include("main.html");
	      break;
		case "createPlan":
	      $fileTemplate="createPlan.html";
	      include("main.html");
	      break;
/*paz*/
		case "moveClient2Plan":
			$fileTemplate="moveClient2Plan.html";
			include("main.html");
			break;
		case "showPlanDetails":
			$fileTemplate="showPlanDetails.html";
			include('showPlanDetails.html');
			break;
		case "showDomains":
			$fileTemplate="showDomains.html";
			include('showDomains.html');
			break;
		case "comparePlans":
			$fileTemplate="comparePlans.html";
			include('comparePlans.html');
			break;
		case "showPlanClientsDetails":
			$fileTemplate="showPlanClientsDetails.html";
			include('showPlanClientsDetails.html');
			break;
		case "planStats":
			$fileTemplate="planStats.html";
			include("main.html");
			break;
		case "showCreatePlanConditions":
			$fileTemplate="showCreatePlanConditions.html";
			include('showCreatePlanConditions.html');
			break;
		#case "managePlans2":
		#	$fileTemplate="managePlans2.html";
		#	include("main.html");
		#	break;
		case "managePlansHelp":
			$fileTemplate="managePlansHelp.html";
			include("managePlansHelp.html");
			break;
/*paz*/
/*nd4wd*/
                case 'stats_general' :
                        $data['reseller_id'] = $id;
			$data['params']['order_status'][1] = 'on';
			$data['options']['limit'] = 50;
                        $data['options']['order_by'] = 'order_id';
                        $data['options']['order_by_'] = 'DESC';
                        $data['options']['group_by'] = array('order_id','order_status','store','store_id','username','sale_type','product_type','payment_currency_','client_blocked','order_date','payed_reseller','store','purchase_expire_date');
			$data['sdate'] = date('Y-m-d',mktime(0,0,0,date('m')-1,1,date('Y')));
			$data['edate'] = date('Y-m-d');
//			$data['edate'] = date('Y-m-d',mktime(0,0,0,date('m')-1,date('t',mktime(0,0,0,date('m')-1,1,date('Y'))),date('Y')));

			$params['order_status'] = array(1,2,4,8,16,32,64,1024,0,128,256,512);
			$params['order_date'] = array('>='.$data['sdate'],'<='.$data['edate']);
                        $params['reseller_id'] = $id;

			$data['res'] = list_sales($params,$data['options']);

			$options2['group_by'] = array('payment_currency_');

			$params2 = $params;

			$params2['sale_type_'] = array('!=reversal');
                        $data['res1']['all'] = list_sales($params2,$options2);

			unset($params2['sale_type_']);
			$data['res1']['ok'] = list_sales($params2,$options2);

			$params2['sale_type_'] = array(' =reversal');
			$params2['order_status'] = array(1,2,4,1024);
			$data['res1']['ref'] = list_sales($params2,$options2);

			$params2['order_status'] = array(8,64);
			$data['res1']['cb'] = list_sales($params2,$options2);

                        include("sales/$action.html");
                break;
                case 'stats_webhosting' :
                        include("sales/$action.html");
                break;
                case 'stats_domains' :
                        $data['reseller_id'] = $id;
			$data['params']['order_status'][1] = 'on';
			$data['params']['domain_status']['all'] = 'on';
			$data['options']['limit'] = 50;
                        $data['options']['order_by'] = 'order_id';
                        $data['options']['order_by_'] = 'DESC';
                        $data['options']['group_by'] = array('order_id','reseller_id','store_id','store','order_status','username','sale_type','product_type','payment_currency_','client_blocked','order_date','payed_reseller','store','purchase_expire_date_','domain_tld','domain_sld','domain_flags');
			$data['sdate'] = date('Y-m-d',mktime(0,0,0,date('m')-1,1,date('Y')));
			$data['edate'] = date('Y-m-d');

			$params['reseller_id'] = $id;
			$params['order_status'] = array(1,2,4,8,16,32,64,1024,0,128,256,512);
			$params['product_type'] = array('res_regdomain','domain','registerdomain','fifty_domain');
			$params['order_date'] = array('>='.$data['sdate'],'<='.$data['edate']);
			$params['domain_flags'] = array(0,1,2,4,5,7,8,9);

			$data['res'] = list_sales($params,$data['options']);

			$options2['group_by'] = array('domain_flags');

			$params2 = $params;

			$params2['order_status'] = array(16,32);
			$data['totals_ok'] = list_sales($params2,$options2);

			$params2['order_status'] = array(1,2,4,1024);
			$data['totals_rf'] = list_sales($params2,$options2);

			$params2['order_status'] = array(8,64);
			$data['totals_cb'] = list_sales($params2,$options2);

			$options2['group_by'] = array('payment_currency_');

			$params2['order_status'] = array(16,32);
			$data['totals_cash'] = list_sales($params2,$options2);

//			echo list_sales($params,$data['options'],'query');
                        include("sales/$action.html");
                break;
                case 'stats_affiliates' :
                	$query = "SELECT reseller_id FROM resellers where referer_id=$id";
                	$master_db->query($query);
                	while($tmp_res=$master_db->getNext()){
                		$data['reseller_id'][] = $tmp_res['reseller_id'];
                	}
                	$master_db->free();

 			$query2 = "SELECT title,store_id FROM stores where reseller_id=$id LIMIT 1";
                	$master_db->query($query2);
                	$data['store_info'] = $master_db->getNext();
			$master_db->free();

			$query3 = "SELECT count(distinct affiliate) FROM affiliates.payments WHERE reseller_id=$id";
			$master_db->query($query3);
			$data[cpanel_affiliates_count] = $master_db->getNext();
			$data[cpanel_affiliates_count] = $data[cpanel_affiliates_count]['count'];
			$master_db->free();

			$data['params']['order_status'][1] = 'on';
			$data['options']['limit'] = 50;
                        $data['options']['order_by'] = 'order_id';
                        $data['options']['order_by_'] = 'DESC';
                        $data['options']['group_by'] = array('order_id','order_status','reseller','username','sale_type','product_type','payment_currency_','client_blocked','order_date','payed_reseller','payed_referer');
			$data['sdate'] = date('Y-m-d',mktime(0,0,0,date('m')-1,1,date('Y')));
			$data['edate'] = date('Y-m-d');

			$params['order_status'] = array(1,2,4,8,16,32,64,1024,0,128,256,512);
			$params['order_date'] = array('>='.$data['sdate'],'<='.$data['edate']);
                        $params['reseller_id'] = $data['reseller_id'];

			if(!$params['reseller_id'] and !$data[cpanel_affiliates_count]){
				$data['no_affiliates'] = true;
			}else{
				if($params['reseller_id']){
					$data['res'] = list_sales($params,$data['options'],'struct','affiliates');

					$options2['group_by'] = array('payment_currency_');

					$params2 = $params;

					$params2['sale_type_'] = array('!=reversal');
					$data['res1']['all'] = list_sales($params2,$options2);

					unset($params2['sale_type_']);
					$data['res1']['ok'] = list_sales($params2,$options2);

					$params2['sale_type_'] = array(' =reversal');

					$params2['order_status'] = array(1,2,4,1024);
					$data['res1']['ref'] = list_sales($params2,$options2);

					$params2['order_status'] = array(8,64);
					$data['res1']['cb'] = list_sales($params2,$options2);

				}else{
					$data['res'] = array('result'=>array(),'num_rows'=>0);

					$data['res1']['all'] = array('result'=>array(),'num_rows'=>0);
					$data['res1']['ok'] = array('result'=>array(),'num_rows'=>0);
				}
				if($data[cpanel_affiliates_count]){
					$cpanel_affiliates_sales = get_cpanel_affiliate_sales_($id,$data['sdate'],$data['edate']);
					$cpanel_affiliates_totals = get_cpanel_affiliate_sales_($id,$data['sdate'],$data['edate'],true);

					$data['res']['result'] = array_merge($data['res']['result'],$cpanel_affiliates_sales);
					$data['res']['num_rows'] = $data['res']['num_rows'] + count($cpanel_affiliates_sales);

					$data['res1']['all']['result'] = array_merge($data['res1']['all']['result'],$cpanel_affiliates_totals);
					$data['res1']['ok']['result'] = array_merge($data['res1']['ok']['result'],$cpanel_affiliates_totals);
//					echo '<pre>';print_r($cpanel_affiliates_totals);
				}
			}

                        include("sales/$action.html");
                break;
                case 'payment_sales' :
                	$data = decode_params($params);
                	$data['reseller_id'] = $id;
   			include("sales/$action.html");
                break;
                case 'payment_history' :
                        $data = decode_params($params);
                        $data['reseller_id'] = $id;
                        $fileTemplate="sales/$action.html";
                        include("main.html");
                break;
                case 'details_domain' :
                        include("main.html");
                        exit;
                break;
                case 'renew_domain' :
                        include("main.html");
                        exit;
                break;

		case 'manageDomains' :
			if($_GET[searched_domain]){
					$start_ajax[] = "loadPage('registerDomains');";
			$start_ajax[] = "searchDomain('search_domain::$_GET[searched_domain]');";
					$GLOBALS['from_page'] = true;
				  }
			include('main.html');
		break;
		case 'accountingManager' :
			include('main.html');
		break;
		case 'dnsActivationLog' :
			include('domain/dns_activation_log.html');
		break;
		case 'statistics' :
			$fileTemplate = "statistics/statistics.html";
			include('main.html');
		break;
		case 'view_invoice' :
			include_once(ROOT_DIR.'rp2/global_functions.php');
			include_once($path.'func.php');

			$dbh = pg_connect("host=$pg_host dbname=$pg_db user=$pg_username password=$pg_password");

			//$invoice_number = $_GET['invoice_number'];
			$invoice_number_parts = explode('-', $invoice_number);

			$order_id = $master_db->escapeStr($invoice_number_parts[3] - $p4);
			$query = "SELECT * FROM orders WHERE order_id=$order_id AND reseller_id=$GLOBALS[id]";
			$master_db->query($query);

			//echo $invoice_number;
			if($master_db->numRows() != 1  or !$invoice_details = load_inv($invoice_number)){
				$Error = 'Invalid invoice/credit note number.';
				echo "<div style='font-size:20px; color:#FF0000;'><strong>{$Error}</strong></div>";
			}else{
				include(LIBS_DIR.'Error/Error.class.php');
				include(LIBS_DIR.'SendMail/SendMail.class.php');
				$mail = new SendMail($master_db, '', '');

				$type = preg_match('/-c/', $invoice_number) ? 'd' : 'a';
				$invoice_details = load_inv($invoice_number);
				$invoice = generate_invoice($invoice_details, $type);
				$blocks = array('BODY1', 'BODY2');
				unset($dbh);

				$invoice = $invoice['variables'];
				$invoice['company_details_'] = $invoice['company_details'];
				$invoice['company_details'] = nl2br($invoice['company_details']);
				$invoice['client_location'] = nl2br($invoice['client_location']);
				$invoice['client_company_name'] = $invoice['client_company_name'] ? $invoice['client_company_name'].'<br />' : '';
				$invoice['client_vat_num'] = $invoice['client_vat_num'] ? "VAT No: $invoice[client_vat_num]<br />" : '';
				$invoice['company_vat'] = $invoice['company_vat'] ? "VAT No. $invoice[company_vat]" : '';
				$invoice['invoice_type'] = strtoupper($invoice['invoice_type']);
				if($invoice['invoice_type'] == 'INVOICE'){
					$invoice['table_style_class'] = 'iTable';
					$invoice['image'] = 'arrow.gif';
					$invoice['font_start'] = '';
					$invoice['font_end'] = '';
					$invoice['payment_details'] = "<tr><td valign='top'></td><td valign='top'><br />".nl2br($invoice['payment_details'])."</td></tr>";
					if($type == 'a'){
						$blocks[] = 'INVOICE_CLIENT';
					}else{
						$blocks[] = 'INVOICE_RESELLER';
					}
				}else{
					$invoice['table_style_class'] = 'cTable';
					$invoice['image'] = 'arrow_c.gif';
					$invoice['font_start'] = '<font color=\'red\'>';
					$invoice['font_end'] = '</font>';
					$invoice['payment_details'] = '';
					if($type == 'a'){
						$blocks[] = 'CREDIT_NOTE_CLIENT';
					}else{
						$blocks[] = 'CREDIT_NOTE_RESELLER';
					}
				}
				$invoice_client = $mail->getEmail($invoice, 'invoices_html', 'default', 0, $blocks);
				print_r($invoice_client['body']);
			}
		break;
		case 'view_self_billing':
			include(ROOT_DIR.'login/accountingManager/func.php');
			include(LIBS_DIR.'Error/Error.class.php');
			include(LIBS_DIR.'SendMail/SendMail.class.php');

			$payment_id = $master_db->escapeStr($payment_id);
			$details = get_self_billing_invoice_details($payment_id);
			$mail = new SendMail($master_db, '', '');
			$self_billing_invoice = $mail->getEmail($details['variables'], 'commission_invoice');
			echo "<table align='center'>
				<tr>
					<td>".nl2br($self_billing_invoice['body'])."</td>
				</tr>
			</table>";
		break;

/*nd4wd*/
/*ogi*/
		case 'tickets':
			include('tickets.php');
			include("main.html");
			exit;
		case 'editTakeaTour':
			$fileTemplate = "take_a_tour.html";
			include("main.html");
			exit;
/*ogi*/
/*kalin*/
		case 'news':
			$fileTemplate="news/index.php";
			include("main.html");
			break;
/*kalin*/
		case 'news_instructions':
			$fileTemplate="news/instructions/index.html";
			include("main.html");
			break;
		default:
	      $fileTemplate="mainPanel.html";
	      include("main.html");
			break;
	}
}
else if(getenv(REQUEST_METHOD) == "POST"){
	switch($action){
		case "changeDetails":
			$info = array();
			$info[reseller]=$_POST[reseller];
			$info[password]=$_POST[password];
			$info[repassword]=$_POST[repassword];
			$info[firstname]=$_POST[firstname];
			$info[lastname]=$_POST[lastname];
			$info[email]=$_POST[email];
			$info[phone]=$_POST[phone];
			$info[address1]=$_POST[address1];
			$info[address2]=$_POST[address2];
			$info[city]=$_POST[city];
			$info[state]=$_POST[state];
			$info[zip]=$_POST[zip];
			$info[country]=$_POST[country];

			$info['company_name'] = $_POST['company_name'];
			$info['vat_registered'] = $_POST['vat_registered'];
			$info['vat_num'] = $_POST['vat_num'];

    		//$info[tax_id]=$_POST[tax_id];
			$info[newsletter]=$_POST[newsletter];

			if($info[password]) {
				if(!validate($info[password])) {
					$errorCode=2;
					$errorMsg = translate('invalid_password');
					$fileTemplate = 'changeDetails.html';
					include('main.html');
					exit();
				}

				if(!validate($info[repassword])) {
					$errorCode=2;
					$errorMsg = translate('invalid_repassword');
					$fileTemplate = 'changeDetails.html';
					include('main.html');
					exit();
				}

				if($info[password]!=$info[repassword]) {
					$errorCode=2;
					$errorMsg = translate('passwords_must_match');
					$fileTemplate = 'changeDetails.html';
					include('main.html');
					exit();
				}

				if(!change_password($id,$info[password])) {
					$errorCode=3;
					$errorMsg = translate('int_error');
					$fileTemplate = 'changeDetails.html';
					include('main.html');
					exit();
				}
				//--------------------------------------------- update on rp2 added by nd4wd
				$sql_queryto = QueryHelper::update('resellers', array('password' =>$info[password]), "reseller_id=$id");
				$master_db->query($sql_queryto);
				$master_db->free();
				//---------------------------------------------
			}

			if(!validate($info[firstname])) {
				$errorCode=3;
				$errorMsg = translate('invalid_firstname');
				$fileTemplate= 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[lastname])) {
				$errorCode=4;
				$errorMsg = translate('invalid_lastname');
				$fileTemplate= 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[email])) {
				$errorCode=5;
				$errorMsg = translate('invalid_email');
				$fileTemplate = 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[phone])) {
				$errorCode=6;
				$errorMsg = translate('invalid_phone');
				$fileTemplate= 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[address1])) {
				$errorCode=7;
				$errorMsg = translate('invalid_address1');
				$fileTemplate= 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[city])) {
				$errorCode=8;
				$errorMsg = translate('invalid_city');
				$fileTemplate = 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[state])) {
				$errorCode=9;
				$errorMsg = translate('invalid_state');
				$fileTemplate = 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[zip])) {
				$errorCode=10;
				$errorMsg = translate('invalid_zip');
				$fileTemplate = 'changeDetails.html';
				include('main.html');
				exit();
			}
			if(!validate($info[country])) {
				$errorCode=11;
				$errorMsg = translate('invalid_country');
				$fileTemplate= 'changeDetails.html';
				include('main.html');
				exit();
			}
			if($info[newsletter]!='yes' && $info[newsletter]!='no') {
				$errorCode=13;
				$errorMsg = translate('invalid_newsletter_settings');
				$fileTemplate = 'changeDetails.html';
				include('main.html');
				exit();
			}

			$resellerInterface = get_interface_settings($id);

			if($resellerInterface['template'] == 15 && empty($info['company_name'])) {
				$errorCode=14;
				$errorMsg = translate('compulsory_company_name1');
				$params['sid'] = $sid;
        $params['action'] = 'editTemplate';
        $errorMsg .= "$baseURL/?".encode_params($params);
				$errorMsg .= translate('compulsory_company_name2');
				$fileTemplate= 'changeDetails.html';
				include('main.html');
				exit();
			}

			if(!change_details($id,$info)) {
				$errorCode=0;
				$errorMsg = translate('int_error');
				$fileTemplate = 'changeDetails.html';
				include('main.html');
				exit();
			}
			//------------------------------------------------------------------------------ update on rp2 added by nd4wd
			$reseller_table_diff = array('id'=>'reseller_id','reseller'=>'name','firstname'=>'first_name','lastname'=>'last_name','current_release_lev'=>'release_level','company_name'=>'company');
			foreach($info as $k=>$v){
				if($reseller_table_diff[$k]){
					$the_key = $reseller_table_diff[$k];
				}else{
					$the_key = $k;
				}
				if(!in_array($k,array('repassword','reseller'))){
					if($k=='newsletter'){
						if($v=='no'){
							$tmp[$the_key] = 'f';
						}elseif($v=='yes'){
							$tmp[$the_key] = 't';
						}
					}elseif($k=='vat_registered'){
						if(trim($v)){
							$tmp[$the_key] = 't';
						}else{
							$tmp[$the_key] = 'f';
						}
					}elseif(($k=='address2' or $k=='company_name') and !trim($v)){
						$tmp[$the_key] = '';
					}else{
						if(trim($v)){
							$tmp[$the_key] = pg_escape_string($v);
						}
					}
				}
			}
			$history_log = new History($master_db);
			$master_db->query("SELECT * FROM resellers where reseller_id=$id");
			$tmp1 = $master_db->getNext();
			$master_db->free();
			$history_record['history_data'] = $history_log->create_history_data($tmp1,$tmp);
			$history_record['history_table'] = 'resellers';
			$history_record['history_type'] = 'update';
			$history_record['reseller_id'] = $id;

			if($history_record['history_data']){
				$history_log->manage_history($history_record,'add');
			}

			$sql_queryto = QueryHelper::update('resellers', $tmp, "reseller_id=$id");
			$master_db->query($sql_queryto);
			$master_db->free();

			//------------------------------------------------------------------------------
			$resellerCountry = $info[country];
//			session_save(sid);
			$okMsg = translate('successfully_modified');
			$fileTemplate = "changeDetails.html";
			include('main.html');
			exit_now();
		break;
		case "changeBankDetails":
	  		$info = "";
	  		$info[current_release_level]=$_POST[current_release_level];
	  		$info[payment_method]=$_POST[payment_method];
	  		$info[swift_code]=$_POST[swift_code];
	  		$info[bank_name]=$_POST[bank_name];
	  		$info[bank_address]=$_POST[bank_address];
	  		$info[account_number]=$_POST[account_number];
	  		$info[routing_number]=$_POST[routing_number];
	  		$info[account_holder]=$_POST[account_holder];
			$info[paypal_email]=$_POST[paypal_email];

	      if($info[payment_method] == 'wire') {
	        if(!validate($info[current_release_level])){ $errorCode=19; $errorMsg= translate('invalid_current_release_level'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	        if($info[current_release_level] < 500) { $errorCode=20; $errorMsg= translate('invalid_release_level_wire'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	        if(!validate($info[payment_method])){ $errorCode=18; $errorMsg= translate('invalid_payment_method'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	        if(!validate($info[swift_code] , 'swift')){ $errorCode=12; $errorMsg= translate('invalid_swift'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
					if(!validate($info[routing_number])){ $errorCode=16; $errorMsg= translate('invalid_routing'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	        if(!validate($info[bank_name])){ $errorCode=13; $errorMsg= translate('invalid_bank_name'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	        if(!validate($info[bank_address])){ $errorCode=14; $errorMsg= translate('invalid_bank_address'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	        if(!validate($info[account_number])){ $errorCode=15; $errorMsg= translate('invalid_account_number'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	        if(!validate($info[account_holder])){ $errorCode=17; $errorMsg= translate('invalid_account_holder'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	      }
			else if($info[payment_method] == 'paypal') {
	      	if(!validate($info[paypal_email] , 'email')){ $errorCode=18; $errorMsg= translate('invalid_paypal'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }
	      }

			//Patch, da ne moje da si smenq nqkoi danni ot 29-to do 6-to chislo na dva posledovatelni meseca
	      $show_flag=0;
	      if( (date('d')<29 && date('d')>6 ) || $signup_date>date('Y-m-d',time()-3600*24*30)) $show_flag=1;
	      if($_SERVER[REMOTE_ADDR]=='83.228.120.103'){
	        $show_flag=1;
	      }
	      if(!$show_flag){
	      	$info[payment_method]='';
	      	$info[current_release_level]='';
	      }
			//----------------------------------------------------------------------------------------------

			if(!change_bank_details($id,$info)){ $errorCode=0; $errorMsg= translate('int_error'); $fileTemplate= 'changeBankDetails.html'; include('main.html');  exit(); }

	      $okMsg = translate('successfully_modified');
	      $fileTemplate = "changeBankDetails.html";
	      include('main.html');
	      exit_now();
			break;
		case "editPlans":

	      /*if (!is_me()) {
				$settings = $_POST[settings];
				$domain_price = $_POST[domain_price];

				while(list($k,$v) = each($settings)) {
					$v[plan] = $k;
					$v[domain_price] = $domain_price;
					$sys = list_plan_details($k,'array');
					$sys = $sys[0];


					if($v[setup_fee] > $sys[setup_fee_max]){ $errorMsg= translate('invalid_max_fee' , array('fee_max' => $sys[setup_fee_max] , 'k' => $k)); $fileTemplate="editPlans.html";include('main.html');exit();}
					if($v[domain_price] > $sys[domain_max_price]){ $errorMsg= translate('invalid_domain_max_price' , array('domain_max' => $sys[domain_max_price] , 'k' => $k)); $fileTemplate="editPlans.html";include('main.html');exit();}
					if($v[domain_price] < $sys[domain_min_price]){ $errorMsg= translate('invalid_domain_min_price' , array('domain_min' => $sys[domain_min_price] , 'k' => $k)); $fileTemplate="editPlans.html";include('main.html');exit();}
					if($v[plan_price] > $sys[plan_max_price]){ $errorMsg= translate('invalid_plan_max_price' , array('plan_max' => $sys[plan_max_price] , 'k' => $k)); $fileTemplate="editPlans.html";include('main.html');exit();}
					if($v[plan_price] < $sys[plan_min_price]){ $errorMsg= translate('invalid_plan_min_price' , array('plan_min' => $sys[plan_min_price] , 'k' => $k)); $fileTemplate="editPlans.html";include('main.html');exit();}

					// sve: tuk niamashe skobi sled if. Slojih poneje ne raboteshe i se opravi. Pregledai dali vsichko e okay.
					if(!change_plan_settings($id,$v)) { echo translate('int_error'); exit;}
				}

				//za RP2
				//if($id=='27'){
				foreach($settings as $name => $price) {
					$new['12']['USD'] = $price[plan_price];
					$q[] = "UPDATE products set price='".base64_encode(serialize($new))."' where reseller_id='$id' and name='$name'";
					$new = "";
				}

				$new['12']['USD'] = $domain_price;
				$q[] = "UPDATE products set price='".base64_encode(serialize($new))."' where reseller_id='$id' and name='com/net/org/us/info/biz' and type='domain'";

				if(is_array($q)) {
					$db['1']['pass'] = $pg_password; //"w9JwRoA";
					$db['1']['user'] = $pg_username; //"root";
					$db['1']['name'] = $pg_db; //"rp2";
					$db['1']['host'] = $pg_host; //"209.25.134.5";

					$dbh2 = pg_connect("dbname=".$db[1][name]." host=".$db[1][host]." user=".$db[1][user]." password=".$db[1][pass]."");

					foreach($q as $qq){
						if(!$result = pg_query($dbh2,$qq)) mail("errors@bastun.net","duplicate service prices fail","$qq");
					}
				}
	        //}
	        //END za RP2
	      	$okMsg = translate('successfully_modified_plan_settings');
	      }*/
	      $fileTemplate = "editPlans.html";
	      include('main.html');
	      exit_now();
			break;
		#case "managePlans2":
		#		$has_domain=$_POST[has_domain];
		#		$has_domain_inplan=$_POST[has_domain_inplan];
		#		$plans=$_POST[plans];

		#		foreach($plans as $p){
		#			if($p[offering]) $off++;
		#			if($p[display_on_index]) $di++;
		#		}

		#		if(!$off) { $errorMsg= translate('no_plan_selected'); $fileTemplate="managePlans2.html";include('main.html');exit();}
		#		if(!$di) { $errorMsg= translate('no_plan_displayed'); $fileTemplate="managePlans2.html";include('main.html');exit();}
		#		if($has_domain_inplan && !$has_domain){ $errorMsg= translate('no_domain_offered');$fileTemplate="managePlans2.html";include('main.html');exit();}
		#		if(!set_plan_settings($id,$plans,$has_domain,$has_domain_inplan))  { $errorMsg= translate('int_error'); $fileTemplate="managePlans2.html";include('main.html');exit();}
		#		if($has_domain && $has_domain_inplan && !set_minimum_domain_price($id)) { $errorMsg= translate('int_error'); $fileTemplate="managePlans2.html";include('main.html');exit();}

		#		include('duplicate_product_offering.php');

		#		$okMsg = translate('successfully_modified_plan_settings');

		#	$fileTemplate = "managePlans2.html";
		#	include('main.html');
		#	exit_now();
		#	break;
		case "sales":
			$sday =$_POST[sday];
			$smonth =$_POST[smonth];
			$syear =$_POST[syear];
			$eday =$_POST[eday];
			$emonth =$_POST[emonth];
			$eyear =$_POST[eyear];

			$details[start] = date("Y-m-d",mktime(0,0,0,$smonth,$sday,$syear));
			$details[end]  = date("Y-m-d",mktime(0,0,0,$emonth,$eday,$eyear));

			$fileTemplate= 'sales.html';
			include('main.html');
			exit_now();
			break;
		case "editStyle":
			$type = $_POST[type];
			$style = $_POST[style];
			$styleName = $_POST[styleName];
			if($type=='style'){
				$val[style] = $styleName;
			}
			else {
				$val[style] = "";
				$val[styleData] = serialize($style);
			}

			if(!set_interface_settings($id,$val)) { $errorMsg= translate('error_changing_interface'); $fileTemplate="editStyle.html";include('main.html');exit();}

      	$okMsg = translate('successfully_modified_interface_settings');
			$fileTemplate = "editStyle.html";
	      include('main.html');
	      exit_now();
			break;
		case "editHeader":
			$type = $_POST[type];
			switch($type){
				case "text":
					$v[headerData] = $_POST[text_data];
					$v[header] = $type;
				break;
				case "banner":
					if ($HTTP_POST_FILES['banner_data']['name']!=NULL){
						move_uploaded_file($_FILES['banner_data']['tmp_name'],$_FILES['banner_data']['tmp_name']."_");
						chmod($HTTP_POST_FILES['banner_data']['tmp_name']."_",0777);
						//chown($HTTP_POST_FILES['banner_data']['tmp_name'],'888.888');
						$cmd = "/usr/local/admin/fileman '888' 'copy' '".$HTTP_POST_FILES[banner_data][tmp_name]."_' '".$baseDIR."u/upload/".$id."_header.jpg'";
						echo `$cmd`;
						if(!is_file($baseDIR."u/upload/".$id."_header.jpg")) { $errorMsg= translate('error_uploading_header_banner'); $fileTemplate="editHeader.html";include('main.html');exit();}
					}
					$v[headerData] = "/upload/".$id."_header.jpg";
					$v[header] = $type;
					break;
				case "flash":
					if ($HTTP_POST_FILES['flash_data']['name']!=NULL){
						move_uploaded_file($_FILES['flash_data']['tmp_name'],$_FILES['flash_data']['tmp_name']."_");
						chmod($HTTP_POST_FILES['flash_data']['tmp_name']."_",0777);
						//chown($HTTP_POST_FILES['flash_data']['tmp_name'],'888.888');
						$cmd = "/usr/local/admin/fileman '888' 'copy' '".$HTTP_POST_FILES[flash_data][tmp_name]."_' '".$baseDIR."u/upload/".$id."_header.swf'";
						echo `$cmd`;
						if(!is_file($baseDIR."u/upload/".$id."_header.swf")) { $errorMsg= translate('error_uploading_header_flash'); $fileTemplate="editHeader.html";include('main.html');exit();}
					}
					$v[headerData] = "/upload/".$id."_header.swf";
					$v[header] = $type;
					break;
				case "custom":
					$v[headerData] = $_POST[custom_data];
					$v[header] = $type;
				break;
			}

			if(!is_array($v)) {
				$errorMsg= translate('error_changing_interface');
				$fileTemplate="editHeader.html";
				include('main.html');
				exit();
			}

			if(!set_interface_settings($id,$v)) {
				$errorMsg = translate('error_changing_interface');
				$fileTemplate="editHeader.html";
				include('main.html');
				exit();
			}

         $okMsg = translate('successfully_modified_interface_settings');
         $fileTemplate = "editHeader.html";
         include('main.html');
         exit_now();

			break;
		case "editFooter":
			$type = $_POST[type];
			switch($type){
				case "text":
					$v[footerData] = $_POST[text_data];
					$v[footer] = $type;
				break;
				case "banner":
					if ($HTTP_POST_FILES['banner_data']['name']!=NULL){
						move_uploaded_file($_FILES['banner_data']['tmp_name'],$_FILES['banner_data']['tmp_name']."_");
						chmod($HTTP_POST_FILES['banner_data']['tmp_name']."_",0777);
						//chown($HTTP_POST_FILES['banner_data']['tmp_name'],'888.888');
						$cmd = "/usr/local/admin/fileman '888' 'copy' '".$HTTP_POST_FILES[banner_data][tmp_name]."_' '".$baseDIR."u/upload/".$id."_footer.jpg'";
						echo `$cmd`;
						if(!is_file($baseDIR."u/upload/".$id."_footer.jpg")) { $errorMsg= translate('error_uploading_footer_banner'); $fileTemplate="editFooter.html";include('main.html');exit();}
					}

					$v[footerData] = "/upload/".$id."_footer.jpg";
					$v[footer] = $type;
					break;
				case "flash":
					if ($HTTP_POST_FILES['flash_data']['name']!=NULL){
						move_uploaded_file($_FILES['flash_data']['tmp_name'],$_FILES['flash_data']['tmp_name']."_");
						chmod($HTTP_POST_FILES['flash_data']['tmp_name']."_",0777);
						//chown($HTTP_POST_FILES['flash_data']['tmp_name'],'888.888');
						$cmd = "/usr/local/admin/fileman '888' 'copy' '".$HTTP_POST_FILES[flash_data][tmp_name]."_' '".$baseDIR."u/upload/".$id."_footer.swf'";
						echo `$cmd`;
						if(!is_file($baseDIR."u/upload/".$id."_footer.swf")) { $errorMsg= translate('error_uploading_footer_flash'); $fileTemplate="editFooter.html";include('main.html');exit();}
					}
					$v[footerData] = "/upload/".$id."_footer.swf";
					$v[footer] = $type;
					break;
				case "custom":
					$v[footerData] = $_POST[custom_data];
					$v[footer] = $type;
					break;
			}

			if(!is_array($v)) { $errorMsg= translate('error_changing_interface'); $fileTemplate="editFooter.html";include('main.html');exit();}
			if(!set_interface_settings($id,$v)){ $errorMsg= translate('error_changing_interface'); $fileTemplate="editFooter.html";include('main.html');exit();}

         $okMsg = translate('successfully_modified_interface_settings');
         $fileTemplate = "editFooter.html";
         include('main.html');
         exit_now();
			break;
		case "editMenu":
			$set[menuItem1] = $_POST[menuItem1];
			$set[menuItemLink1] = $_POST[menuItemLink1];
			$set[menuItem2] = $_POST[menuItem2];
			$set[menuItemLink2] = $_POST[menuItemLink2];
			$set[menuItem3] = $_POST[menuItem3];
			$set[menuItemLink3] = $_POST[menuItemLink3];
			$t1 = $_POST[t1];
			$t2 = $_POST[t2];
			$t3 = $_POST[t3];
			if($t1) $set[menuItemLink1] = $set[menuItemLink1]."|$t1";
			if($t2) $set[menuItemLink2] = $set[menuItemLink2]."|$t2";
			if($t3)	$set[menuItemLink3] = $set[menuItemLink3]."|$t3";


			if(!is_array($set)) { $errorMsg= translate('error_changing_interface'); $fileTemplate="editFooter.html";include('main.html');exit();}
			if(!set_interface_settings($id,$set)){ $errorMsg= translate('error_changing_interface'); $fileTemplate="editMenu.html";include('main.html');exit();}
                        $okMsg = translate('successfully_modified_interface_settings');
                        $fileTemplate = "editMenu.html";
                        include('main.html');
                        exit_now();

			break;
		case "editTemplate":
			$template = $_POST['template'];

			if(!isset($template)) {
				$errorMsg = translate('error_changing_interface');
				$fileTemplate = 'editTemplate.html';
				include('main.html');
				exit();
			}

			$v['template'] = $template;

			// sve: change company name
			$resellerDetails = list_details($id, 'array');
			$resellerDetails = $resellerDetails[0];

			if ($template == 15 && empty($resellerDetails['company_name'])) {
				$company_name = $_POST['company_name'];

				if(empty($company_name)) {
					$errorCode = 1;
					$errorMsg = translate('error_missing_company_name');
					$fileTemplate = 'editTemplate.html';
					include('main.html');
					exit();
				}
				else {
					change_company_mysql($id, $company_name);
					change_company_pgsql($master_db, $id, $company_name);
				}
			}
			// end: change company name

			if(!set_interface_settings($id,$v)) {
				$errorMsg = translate('error_changing_interface');
				$fileTemplate = 'editTemplate.html';
				include('main.html');
				exit();
			}

			// sve: set about us default texts
			// get reseller details for default text
			$resellerDetails = list_details($id, 'array');
			$resellerDetails = $resellerDetails[0];

			$replaceStrings = array (
				'%store_name%' => $store_name,
				'%company_name%' => $resellerDetails['company_name'],
				'%country%' => get_country_name($resellerDetails['country']),
				'%city%' => $resellerDetails['city'],
				'%state%' => $resellerDetails['state'],
			);

			// replace values in the text
			foreach ($store_aboutus_data as $key => $value) {
				foreach($replaceStrings as $replaceKey => $replaceValue) {
					$value = str_replace($replaceKey, $replaceValue, $value);
					$store_aboutus_data[$key] = str_replace($replaceKey, $replaceValue, $value);
				}
			}

			set_aboutus($master_db, $old['resellers']['id'], $store_aboutus_data, 'abous_us');
			// end: set about us default texts

			if ($template == 15) {
				$okMsg = translate('confirmation_message1');

				$params['sid'] = $sid;
        $params['action'] = 'editAboutUs';

        $okMsg .= "$baseURL/?".encode_params($params);
        $okMsg .= translate('confirmation_message2');
			}
			else {
				$okMsg = translate('successfully_modified_interface_settings');
			}

			$fileTemplate = "editTemplate.html";

			include('main.html');
			exit_now();
			break;
		case "editRemoteTemplate":
			$fileTemplate = "editRemoteTemplate.html";
			include('main.html');
			exit_now();
		break;
		case "editRemoteFormsDomain":
			$fileTemplate="editRemoteFormsDomain.html";
			include("main.html");
			break;
		case "editRemoteFormsOrder":
			$fileTemplate="editRemoteFormsOrder.html";
			include("main.html");
			break;
		case "editDescription":
			//error msgs gi ostaviam za translate, tai kato editDescription.html ne raboti - static
			$plan = $_POST[plan];
			$sel = $_POST[sel];
			$defaults = $_POST[defaults];


			if(!$plan){ $errorMsg="Error 1"; $fileTemplate="editDescription.html";include('main.html');exit();}
			if(!is_array($sel)){  $errorMsg="Error 2 "; $fileTemplate="editDescription.html";include('main.html');exit();}
			if($defaults) {
				if(!set_default_description($id,$plan)){$errorMsg="Error 3"; $fileTemplate="editDescription.html";include('main.html');exit();}
			}
			else{
				$description = implode("|",$sel);
				if(!set_reseller_description($id,$plan,$description)){ $errorMsg="Error 3 "; $fileTemplate="editDescription.html";include('main.html');exit();}
			}

                        $okMsg = translate('successfully_modified_settings');
                        $fileTemplate = "editDescription.html";
                        include('main.html');
                        exit_now();

		break;
		case "add_domain":
			if($_POST[search_domain]){
				$domain_search_result = search4domains($_POST[search_domain],'bTable');
				if(!$domain_search_result){
					$errorMsg = translate('invalid_domain_name');
				}
				$fileTemplate = "domain.html";
				include('main.html');
				exit_now();
			}

			$domain=strtolower($_POST[domain]);
			$pass=$_POST[pass];
			$repass=$_POST[repass];
			$register_domain=$_POST[register_domain];
			$domain_search_result = search4domains($domain);

			if (strlen($domain) > 63 || !ereg("^([a-z0-9][a-z0-9-]?)*[a-z0-9]\\.([a-z]{2,4})(\\.[a-z]{2,4})?$", $domain)){$domain=''; $errorMsg = translate('invalid_domain_name'); $fileTemplate="domain.html"; include('main.html'); exit();}

                        if(!$register_domain and preg_match("/\.com\$|\.net\$|\.org\$|\.biz\$|\.info\$|\.us\$/",$domain)){
                                if($domain_search_result[$domain]=='available'){
                                        $errorMsg = 'This Domain is not registered';
                                        $fileTemplate="domain.html";
                                        include('main.html');
                                        exit();
                                }
                        }

                        if(!$pass) {$errorMsg = translate('invalid_password_any');$fileTemplate="domain.html";include('main.html');exit();}
                        if($pass!=$repass) {$errorMsg = translate('invalid_repassword');$fileTemplate="domain.html";include('main.html');exit();}

			if(domain_exist($domain)){$errorMsg = translate('domain_exist');$fileTemplate="domain.html";include('main.html');exit();}

			if($register_domain){
				if(!ereg("^([a-z0-9][a-z0-9-]?)*[a-z0-9]\\.([a-z]{2,4})$", $domain)){$errorMsg = translate('invalid_domain_name');$fileTemplate="domain.html";include('main.html');exit();}
				$arr=explode(".",$domain);
				if(!strstr("com|net|org|biz|info|us",$arr[1])){$errorMsg = translate('invalid_domain_tld');$fileTemplate="domain.html";include('main.html');exit();}
				include("../ggg.php");
				$info[id]=$id;
				$info[sid]=$sid;
				$info[pass]=$pass;
				$info[domain]=$domain;
				while(list($k,$v)=each($_POST[info])){
					$info[$k]=$v;
				}

                                $info['country'] = $_POST['country'];
                                $info['company_name'] = $_POST['company_name'];
                                $info['vat_registered'] = $_POST['vat_registered'];
                                $info['vat_num'] = $_POST['vat_num'];
                                include_once('init_valid_user.php');
                                $user_validator->validate_array($info,false);
                                if(!$user_validator->validate_array($info,false)){
					$err_str = array_flip(array_reverse($user_validator->validate_returned));
//					echo '<pre>';print_r($info);print_r($user_validator->validate_returned);
					$error_msg_arr = array(
						'firstname'=>'First Name',
						'lastname'=>'Last Name',
						'password'=>'Password',
						'email'=>'Email',
						'address1'=>'Address1',
						'address2'=>'Address2',
						'city'=>'City',
						'state'=>'State',
						'zip'=>'Zip',
						'country'=>'Country',
						'phone'=>'Phone',
						'fax'=>'Fax',
						'company_name'=>'Company Name',
						'vat_num' => 'Vat Number'
					);
					$errorMsg = 'Invalid '.$error_msg_arr[($err_str[0])];
					$fileTemplate="domain.html";
					include('main.html');
					exit();
                                }

				if(!temporary_register_domain($info)) {$errcode="12";$errorMsg = translate('int_error');$fileTemplate="domain.html";include('main.html');exit();}

//				session_register_('mailbox_pass');
//				session_register_('domain4registration');
				$mailbox_pass = $pass;
				$domain4registration = $domain;
                                $_SESSION['mailbox_pass'] = $mailbox_pass;
                                $_SESSION['domain4registration'] = $domain4registration;
                                $_SESSION['reg_domain_success'] = true;                                
                                
				if($domain_search_result[$domain]=='notavailable'){
					$info[domain_registration_type] = 2;
				}
				$fileTemplate = 'domain/ResellerDomainRegistration.html';
				include('main.html');
//				session_save(sid);
				exit_now();
			}

			if(!add_domain_mailbox_email($id,$domain,$pass)){$errorMsg = translate('error_creating_domain_mailbox');$fileTemplate="domain.html";include('main.html');exit();}
			$okMsg = translate('successfully_added_domain');

//			session_save(sid);
			$params[sid]=$sid;
			$params[action]='add_domain';
			$url="$baseURL/?".encode_params($params);
			header("Location: $url");
			exit_now();
		break;

		case "emails":
			$email=$_POST[email];
			$domain=$_POST[domain];

			if(!$email) {$errorMsg = translate('create_alias');$fileTemplate="emails.html";include('main.html');exit();}

			if(!preg_match('/(^[^\000-\037\'"^\']+$|^[0-9a-z]+([-]?[0-9a-z])*\.[a-z]{2,4}(\\.[a-z]{2,4})?$)/',"$email@$domain")) {$errorMsg = translate('invalid_email_alias');$fileTemplate="emails.html";include('main.html');exit();}

			if(!add_email($domain,$email)){$errorMsg = translate('int_error');$fileTemplate="emails.html";include('main.html');exit();}

			//if($domain!=get_reseller_domain($id)) exit("Fatal error!");
			/*
			include_once("../hosting_connect/call.php");
			$func[function_name]="add_email";
        		$func[params][domain]=$domain;
		        $func[params][email]="$email@$domain";
        		$res=call_remote_method($func);

			if(!$res){$errorMsg = "Error please contact the support";$fileTemplate="emails.html";include('main.html');exit();}
			*/

      $okMsg = translate('successfully_added_alias');
//      session_save(sid);
      $params[sid]=$sid;
      $params[action]='emails';
      $url="$baseURL/?".encode_params($params);
      header("Location: $url");
      exit_now();
		break;
		case "del_emails":
			$emails=$_POST[emails];
			$domain=list_reseller_domains($id,'array');
			if(!is_array($emails)) {$errorMsg = translate('no_emails_selected_delete');$fileTemplate="emails.html";include('main.html');exit();}
			foreach($emails as $mail){
				$k=explode("@",$mail);
				if($k[0]=="sales") {$errorMsg = translate('error_delete_sales_email');$fileTemplate="emails.html";include('main.html');exit();}

				if(!in_array ($k[1],$domain)) {$errorMsg = translate('int_error');$fileTemplate="emails.html";include('main.html');exit();}
			}

			if(!delete_emails($emails)) {$errorMsg = translate('int_error');$fileTemplate="emails.html";include('main.html');exit();}

			$okMsg = translate('successfully_deleted_email');
			//session_save(sid);
			$params[sid]=$sid;
			$params[action]="emails";
			$url="$baseURL/?".encode_params($params);
			header("Location: $url");
			exit_now();

		break;
		case "del_domains":
			$domains=$_POST[domains];
                        if($_POST['add_param']){
                          $domains[] = $_POST['add_param'];
                        }
			$dom=list_reseller_domains($id,'array');
			if(!is_array($domains)) {$errorMsg = translate('no_domains_selected_delete');$fileTemplate="domain.html";include('main.html');exit();}
			foreach($domains as $d){
				if(!in_array($d,$dom))	{$errorMsg = translate('int_error');$fileTemplate="domain.html";include('main.html');exit();}
			}
			if(!delete_domain_mailbox_email($id,$domains)) {$errorMsg = translate('error_delete_domain');$fileTemplate="domain.html";include('main.html');exit();}

			$okMsg = translate('successfully_deleted_domain');
			//session_save(sid);
			$params[sid]=$sid;
			$params[action]="add_domain";
      $url="$baseURL/?".encode_params($params);
      header("Location: $url");
      exit_now();
		break;
		case "chng_pass_mailbox":
			$pass=$_POST[pass];
			$repass=$_POST[repass];
			$mailbox=$_POST[mailbox];

			if(!$pass) {$errorMsg = translate('no_email_password');$fileTemplate="emails.html";include('main.html');exit();}
			if($pass!=$repass) {$errorMsg = translate('invalid_password_any');$fileTemplate="emails.html";include('main.html');exit();}
			if(!in_array($mailbox,list_reseller_domains($id,'array')))  {$errorMsg = translate('int_error');$fileTemplate="emails.html";include('main.html');exit();};
			if(!change_mailbox_pass($pass,$mailbox)) {$errorMsg = translate('error_settings_password');$fileTemplate="emails.html";include('main.html');exit();}

			$okMsg = translate('successfully_changed_email_password');
			//session_save(sid);
      $params[sid]=$sid;
			$params[action]="emails";
      $url="$baseURL/?".encode_params($params);
      header("Location: $url");
      exit_now();
		break;
		case "editStoreName":
			$store_name = $_POST[store_name];

			if(!$store_name) {$errorMsg = translate('invalid_store_name');$fileTemplate="editStoreName.html";include('main.html');exit();}
			if(!set_store_name($id,$store_name))  {$errorMsg = translate('error_setting_store_name');$fileTemplate="editStoreName.html";include('main.html');exit();}

	            //duplicate store name/title
                      $db['1']['pass'] = $pg_password; //"w9JwRoA";
                      $db['1']['user'] = $pg_username; //"root";
                      $db['1']['name'] = $pg_db; //"rp2";
                      $db['1']['host'] = $pg_host; //"209.25.134.5";

                      $q = "UPDATE stores set title='".$store_name."' where reseller_id='".$id."'";

                      $dbh2 = pg_connect("dbname=".$db[1][name]." host=".$db[1][host]." user=".$db[1][user]." password=".$db[1][pass]."");
                      if(!$result = pg_query($dbh2,$q)) mail("cbfl@bastun.net","duplicate Store Name fail","$q");

		    $okMsg = translate('successfully_changed_store_name');
		    $fileTemplate = "editStoreName.html";
		    include('main.html');
		    exit_now();

		break;
		case "editServicePrices":
			$data = $_POST['data'];
			
			$dataCheck = get_reseller_service_prices($id);
						
			if($data[$dataCheck['disk_space']['product_id']] < monthly_price($dataCheck['disk_space']['min_price']))  {$errorMsg = translate('invalid_upgrade_storage_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['traffic']['product_id']] < monthly_price($dataCheck['traffic']['min_price']))  {$errorMsg = translate('invalid_upgrade_traffic_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['domain']['product_id']] < monthly_price($dataCheck['domain']['min_price'])) {$errorMsg = translate('invalid_upgrade_domain_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['ip']['product_id']] < monthly_price($dataCheck['ip']['min_price']))  {$errorMsg = translate('invalid_upgrade_ip_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['sql']['product_id']] < monthly_price($dataCheck['sql']['min_price'])) {$errorMsg = translate('invalid_upgrade_db_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['sql_quota']['product_id']] < monthly_price($dataCheck['sql_quota']['min_price'])) {$errorMsg = translate('invalid_upgrade_dbspace_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['com/net/org/us/info/biz']['product_id']] < yearly_price($dataCheck['com/net/org/us/info/biz']['min_price'])) {$errorMsg = translate('invalid_upgrade_regdomain_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}


			if($data[$dataCheck['disk_space']['product_id']] > monthly_price($dataCheck['disk_space']['max_price']))  {$errorMsg = translate('invalid_upgrade_storage_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['traffic']['product_id']] > monthly_price($dataCheck['traffic']['max_price']))  {$errorMsg = translate('invalid_upgrade_traffic_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['domain']['product_id']] > monthly_price($dataCheck['domain']['max_price'])) {$errorMsg = translate('invalid_upgrade_domain_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['ip']['product_id']] > monthly_price($dataCheck['ip']['max_price']))  {$errorMsg = translate('invalid_upgrade_ip_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['sql']['product_id']] > monthly_price($dataCheck['sql']['max_price'])) {$errorMsg = translate('invalid_upgrade_db_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['sql_quota']['product_id']] > monthly_price($dataCheck['sql_quota']['max_price'])) {$errorMsg = translate('invalid_upgrade_dbspace_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if($data[$dataCheck['com/net/org/us/info/biz']['product_id']] > yearly_price($dataCheck['com/net/org/us/info/biz']['max_price'])) {$errorMsg = translate('invalid_upgrade_regdomain_price'); $fileTemplate="editServicePrices.html";include('main.html');exit();}
			if ($data[$dataCheck['ssh']['product_id']] < monthly_price($dataCheck['ssh']['min_price']) || $data[$dataCheck['ssh']['product_id']] > monthly_price($dataCheck['ssh']['max_price'])) { $errorMsg = translate('invalid_upgrade_ssh_price'); $fileTemplate = 'editServicePrices.html'; include('main.html'); exit(); }
			
			if(!set_reseller_service_prices($id, $data, $dataCheck)) {
				$errorMsg = translate('int_error');
				$fileTemplate="editServicePrices.html";
				include('main.html');
				exit();
			}

	    $okMsg = translate('successfully_changed_upgrades');
	    $fileTemplate = "editServicePrices.html";
	    include('main.html');
	    exit_now();

		break;
		case "manageEmailNotifications":
			$fileTemplate="manageEmailNotifications.html";
			include("main.html");
			break;
		case "editMeta":
			$data = $_POST[set];
			foreach($data as $d){
				if(is_array($d)){ if(count(array_unique($d))>1) $count++;}
				else if($d) $count++;
			}
			if($count > 0 && $count < 3) {$errorMsg = translate('invalid_meta_data');$fileTemplate="editMeta.html";include('main.html');exit();}
			if(is_array($data[keywords])) $data[keywords] = implode(", ",array_unique($data[keywords]));
			if(is_array($data[classification])) $data[classification] = implode(", ",array_unique($data[classification]));
			if(!set_meta_settings($id,$data)) {$errorMsg = translate('int_error');$fileTemplate="editMeta.html";include('main.html');exit();}

      							$okMsg = translate('successfully_changed_metatags');
							  		$fileTemplate = "editMeta.html";
							      include('main.html');
							      exit_now();

		break;
		case "editContacts":
			$contacts = $_POST[contacts];
			if(!set_contacts($id,$contacts))  {$errorMsg = translate('int_error');$fileTemplate="editContacts.html";include('main.html');exit();}

			$okMsg= translate('successufully_changed_contacts');
			$fileTemplate = "editContacts.html";
			include('main.html');
			exit_now();

			break;
		case "editAboutUs":
			$aboutUs = $_POST['aboutus'];
			if(set_aboutus($master_db, $id, $aboutUs, 'about_us') === false)  {
				$errorMsg = translate('int_error');
				$fileTemplate="editAboutUs.html";
				include('main.html');
				exit();
			}

			// set TRUE on displaying OK message
			$okMsg = true;

			$fileTemplate = "editAboutUs.html";
			include('main.html');
			exit_now();
			break;
		case "stats":
			$stats_domain = $_POST[stats_domain];
			$_SESSION['stats_domain'] = $stats_domain;
//			session_register_(stats_domain);
//			session_save(sid);
			$params="";
			$fileTemplate="stats.html";
			include("main.html");
			exit_now();
			break;
		case "renewClientTotal":
			$fileTemplate="renewClientTotal.html";
			include("main.html");
			break;
    case "editW9Form":
      if(!$data['name'] = $_POST['name']) {$errorMsg = translate('w9_invalid_name');$fileTemplate="editW9Form.html";include('main.html');exit();}

			$data['company'] = $_POST['company'];

			if(!$data['entityType'] = $_POST['entityType']) {$errorMsg = translate('w9_invalid_type');$fileTemplate="editW9Form.html";include('main.html');exit();}
      if($data['entityType'] == 'O') {
      	if(!$data['entityTypeDescription'] = $_POST['entityTypeDescription']) {$errorMsg = translate('w9_invalid_desc');$fileTemplate="editW9Form.html";include('main.html');exit();}
      }
      $data['backupWithHoldingExempt'] = $_POST['backupWithHoldingExempt'];

      if(!$data['address'] = $_POST['address']) {$errorMsg = translate('w9_invalid_address');$fileTemplate="editW9Form.html";include('main.html');exit();}
      if(!$data['city'] = $_POST['city']) {$errorMsg = translate('w9_invalid_city');$fileTemplate="editW9Form.html";include('main.html');exit();}
      if(!$data['stateProvince'] = $_POST['stateProvince']) {$errorMsg = translate('w9_invalid_state');$fileTemplate="editW9Form.html";include('main.html');exit();}
      if(!$data['postalCode'] = $_POST['postalCode']) {$errorMsg = translate('w9_invalid_zip');$fileTemplate="editW9Form.html";include('main.html');exit();}

      $data['country'] = 'US';

      $data['accountReference'] = $_POST['accountReference'];
      if(!$data['tinNumber'] = $_POST['tinNumber']) {$errorMsg = translate('w9_invalid_tin');$fileTemplate="editW9Form.html";include('main.html');exit();}
      if(!$data['tinType'] = $_POST['tinType']) {$errorMsg = translate('w9_invalid_tin_type');$fileTemplate="editW9Form.html";include('main.html');exit();}
      if(!$data['username'] = $_POST['username']) {$errorMsg = translate('w9_invalid_signature');$fileTemplate="editW9Form.html";include('main.html');exit();}
      $data['id'] = $id;
      if(!w9_insert($data)) {
      	$errorMsg = translate('w9_int_error');
      	$fileTemplate = "editW9Form.html";
      	include('main.html');
      	exit();
      }
      
      $query = "UPDATE rscp_home SET w9_form = true WHERE reseller_id = {$id}";
      $master_db->query($query);
      // rp2 update error
      if (!empty($master_db->error)) {
      	$errorMsg = translate('w9_int_error');
      	$fileTemplate = "editW9Form.html";
      	include('main.html');
      	exit();
      }
      
      $okMsg = translate('w9_successfully_submitted');
      $fileTemplate="mainPanel.html";
      include("main.html");
      break;
		case 'editApiSettings';
			$fileTemplate="editApiSettings.html";
      include("main.html");
		break;
		case "walletAccountRefill":
			include('../rp2/global_functions.php');
			include('../rp2/mail_functions.php');
			include('../rp2/functions.php');
			include('wallet_db.html');
			include('walletAccountRefill_POST.html');
			exit_now();
		break;
		case "walletPaymentHistory":
      $fileTemplate="walletPaymentHistory.html";
      include("main.html");
      break;
    case "walletSettings":
      $fileTemplate="walletSettings.html";
      include("main.html");
      break;
    case "currencyExchange":
      $fileTemplate="currencyExchange.html";
      include("main.html");
      break;
    case "currencyExchangeHistory":
      $fileTemplate="currencyExchangeHistory.html";
      include("main.html");
      break;
		case "editClientsUpgrades":
      $fileTemplate="editClientsUpgrades.html";
      include("main.html");
      break;
		case "manualUpgrades":
      $fileTemplate="manualUpgrades.html";
      include("main.html");
      break;
		case "check_domain_availability":
      $fileTemplate="domain/check_domain_availability.html";
      include("main.html");
      break;
		case "register_domain":
      $fileTemplate="domain/register_domain.html";
      include("main.html");
      break;
		case "changedetails":
      $fileTemplate="domain/changedetails.html";
      include("main.html");
			break;
		case "domain_renew":
      $fileTemplate="domain/domain_renew.html";
      include("main.html");
	    break;
		case "createPlan":
      $fileTemplate="createPlan.html";
      include("main.html");
      break;
/*paz*/
    case "moveClient2Plan":
      $fileTemplate="moveClient2Plan.html";
      include("main.html");
      break;
    case "showPlanDetails":
      $fileTemplate="showPlanDetails.html";
      include('showPlanDetails.html');
      break;
    case "showDomains":
      $fileTemplate="showDomains.html";
      include('showDomains.html');
      break;
    case "comparePlans":
      $fileTemplate="comparePlans.html";
      include('comparePlans.html');
      break;
    case "showPlanClientsDetails":
      $fileTemplate="showPlanClientsDetails.html";
      include('showPlanClientsDetails.html');
      break;
    case "planStats":
      $fileTemplate="planStats.html";
      include("main.html");
      break;
    case "showCreatePlanConditions":
      $fileTemplate="showCreatePlanConditions.html";
      include('showCreatePlanConditions.html');
      break;
     case "managePlans":
			$fileTemplate="managePlans.html";
			include("main.html");
			break;
/*paz*/

/*nd4wd*/

	case 'stats_general' :
		$data = $_POST;
		$data['reseller_id'] = $id;
		$params = array();
//currency
		if($data['params']['payment_currency'] and in_array($data['params']['payment_currency'],array('USD','GBP','EUR','CAD','AUD'))){
			$params['payment_currency'] = $data['params']['payment_currency'];
		}
//date
		if(trim($data[sdate])){
			$params['order_date'][] = ">=".$data['sdate'];
		}
		if(trim($data[edate])){
			$params['order_date'][] = "<=".$data['edate'];
		}
//order_status
		if($data['params']['order_status'][2]){
			$params['order_status'] = array_merge($params['order_status'],array(16,32));
		}
		if($data['params']['order_status'][3]){
			$params['order_status'] = array_merge($params['order_status'],array(1,2,4,1024));

		}
		if($data['params']['order_status'][4]){
			$params['order_status'] = array_merge($params['order_status'],array(8,64));
		}
		if(!$params['order_status'] or $data['params']['order_status'][1]){
			$params['order_status'] = array(1,2,4,8,16,32,64,1024,0,128,256,512);
		}

//additional
		$params[reseller_id] = $id;

//options
		$data['options']['group_by'] = array('order_id','order_status','store_id','store','username','sale_type','product_type','payment_currency_','client_blocked','order_date','payed_reseller','store','purchase_expire_date');
		$data['options']['order_by'] = 'order_id';
		$data['options']['order_by_'] = 'DESC';

//list
		$data['res'] = list_sales($params,$data['options']);

		$options2['group_by'] = array('payment_currency_');

		$params2 = $params;

		$params2['sale_type_'] = array('!=reversal');
		$data['res1']['all'] = list_sales($params2,$options2);

		unset($params2['sale_type_']);
		$data['res1']['ok'] = list_sales($params2,$options2);

		$params2['sale_type_'] = array(' =reversal');

		$params2['order_status'] = array(1,2,4,1024);
		$data['res1']['ref'] = list_sales($params2,$options2);

		$params2['order_status'] = array(8,64);
		$data['res1']['cb'] = list_sales($params2,$options2);

		include("sales/$action.html");
	break;
	case 'stats_webhosting' :
		include("sales/$action.html");
	break;
	case 'stats_domains' :
			$data = $_POST;
			$data['reseller_id'] = $id;
                        $data['options']['order_by'] = 'order_id';
                        $data['options']['order_by_'] = 'DESC';
			$data['options']['group_by'] = array('order_id','reseller_id','store_id','store','order_status','username','sale_type','product_type','payment_currency_','client_blocked','order_date','payed_reseller','store','purchase_expire_date_','domain_tld','domain_sld','domain_flags');
			$params = array();
			if($data['params']['payment_currency'] and in_array($data['params']['payment_currency'],array('USD','GBP','EUR','CAD','AUD'))){
				$params['payment_currency'] = $data['params']['payment_currency'];
			}

//order_date
			if(trim($data[sdate])){
				$params['order_date'][] = ">=".$data['sdate'];
			}
			if(trim($data[edate])){
				$params['order_date'][] = "<=".$data['edate'];
			}
//exp periods
			if($data['expiring']){
				$params['purchase_expire_date_'][] = ' >'.date('Y-m-d');
				$params['purchase_expire_date_'][] = '<='.date('Y-m-d',mktime(0,0,0,date('m'),date('d')+$data['expiring'],date('Y')));
			}
			if($data['expired']){
				$params['purchase_expire_date_'][] = '<='.date('Y-m-d');
				$params['purchase_expire_date_'][] = '>='.date('Y-m-d',mktime(0,0,0,date('m'),date('d')-$data['expired'],date('Y')));
			}
//order_status
			if($data['params']['order_status'][2]){
				$params['order_status'] = array_merge($params['order_status'],array(16,32));
			}
			if($data['params']['order_status'][3]){
				$params['order_status'] = array_merge($params['order_status'],array(1,2,4,1024));

			}
			if($data['params']['order_status'][4]){
				$params['order_status'] = array_merge($params['order_status'],array(8,64));
			}
			if(!$params['order_status'] or $data['params']['order_status'][1]){
				$params['order_status'] = array(1,2,4,8,16,32,64,1024,0,128,256,512);
			}
//domain_status
			if($data['params']['domain_status']){
				if($data['params']['domain_status']['all']){
					$params['domain_flags'] = array(0,1,2,4,5,7,8,9);
				}else{
					$params['domain_flags'] = array_keys($data['params']['domain_status']);
				}
			}else{
				$data['params']['domain_status']['all'] = 'on';
				$params['domain_flags'] = array(0,1,2,4,5,7,8,9);
			}

			$params[reseller_id] = $id;
			$params['product_type'] = array('res_regdomain','domain','registerdomain','fifty_domain');

			$data['res'] = list_sales($params,$data['options']);

                        $options2['group_by'] = array('domain_flags');

                        $params2 = $params;

                        $params2['order_status'] = array(16,32);
                        $data['totals_ok'] = list_sales($params2,$options2);

                        $params2['order_status'] = array(1,2,4,1024);
                        $data['totals_rf'] = list_sales($params2,$options2);

                        $params2['order_status'] = array(8,64);
                        $data['totals_cb'] = list_sales($params2,$options2);

			$options2['group_by'] = array('payment_currency_');

                        $params2['order_status'] = array(16,32);
                        $data['totals_cash'] = list_sales($params2,$options2);

//                      echo list_sales($params,$data['options'],'query');

                        include("sales/$action.html");
	break;
	case 'stats_affiliates' :
			$data = $_POST;
                	$query = "SELECT reseller_id FROM resellers where referer_id=$id";
                	$master_db->query($query);
                	while($tmp_res=$master_db->getNext()){
                		$data['reseller_id'][] = $tmp_res['reseller_id'];
                	}
                	$master_db->free();

 			$query2 = "SELECT title,store_id FROM stores where reseller_id=$id LIMIT 1";
                	$master_db->query($query2);
                	$data['store_info'] = $master_db->getNext();
			$master_db->free();

			$query3 = "SELECT count(distinct affiliate) FROM affiliates.payments WHERE reseller_id=$id";
			$master_db->query($query3);
			$data[cpanel_affiliates_count] = $master_db->getNext();
			$data[cpanel_affiliates_count] = $data[cpanel_affiliates_count]['count'];
			$master_db->free();

                        $data['options']['order_by'] = 'order_id';
                        $data['options']['order_by_'] = 'DESC';
                        $data['options']['group_by'] = array('order_id','order_status','reseller','username','sale_type','product_type','payment_currency_','client_blocked','order_date','payed_reseller','payed_referer');

			$params = array();
			$params['reseller_id'] = $data['reseller_id'];
			if($data['params']['payment_currency'] and in_array($data['params']['payment_currency'],array('USD','GBP','EUR','CAD','AUD'))){
				$params['payment_currency'] = $data['params']['payment_currency'];
			}

			if(trim($data[sdate])){
				$params['order_date'][] = ">=".$data['sdate'];
			}
			if(trim($data[edate])){
				$params['order_date'][] = "<=".$data['edate'];
			}

			if($data['params']['order_status'][2]){
				$params['order_status'] = array_merge($params['order_status'],array(16,32));
			}
			if($data['params']['order_status'][3]){
				$params['order_status'] = array_merge($params['order_status'],array(1,2,4,1024));

			}
			if($data['params']['order_status'][4]){
				$params['order_status'] = array_merge($params['order_status'],array(8,64));
			}
			if(!$params['order_status'] or $data['params']['order_status'][1]){
				$params['order_status'] = array(1,2,4,8,16,32,64,1024,0,128,256,512);
			}

			if(!$params['reseller_id'] and !$data[cpanel_affiliates_count]){
				$data['no_affiliates'] = true;
			}else{
				if($params['reseller_id']){
					$data['res'] = list_sales($params,$data['options'],'struct','affiliates');

					$options2['group_by'] = array('payment_currency_');

					$params2 = $params;

					$params2['sale_type_'] = array('!=reversal');
					$data['res1']['all'] = list_sales($params2,$options2);

					unset($params2['sale_type_']);
					$data['res1']['ok'] = list_sales($params2,$options2);

					$params2['sale_type_'] = array(' =reversal');

					$params2['order_status'] = array(1,2,4,1024);
					$data['res1']['ref'] = list_sales($params2,$options2);

					$params2['order_status'] = array(8,64);
					$data['res1']['cb'] = list_sales($params2,$options2);
				}else{
					$data['res'] = array('result'=>array(),'num_rows'=>0);

					$data['res1']['all'] = array('result'=>array(),'num_rows'=>0);
					$data['res1']['ok'] = array('result'=>array(),'num_rows'=>0);
				}

				if($data[cpanel_affiliates_count]){
					$cpanel_affiliates_sales = get_cpanel_affiliate_sales_($id,$data['sdate'],$data['edate']);
					$cpanel_affiliates_totals = get_cpanel_affiliate_sales_($id,$data['sdate'],$data['edate'],true);

					$data['res']['result'] = array_merge($data['res']['result'],$cpanel_affiliates_sales);
					$data['res']['num_rows'] = $data['res']['num_rows'] + count($cpanel_affiliates_sales);

					$data['res1']['all']['result'] = array_merge($data['res1']['all']['result'],$cpanel_affiliates_totals);
					$data['res1']['ok']['result'] = array_merge($data['res1']['ok']['result'],$cpanel_affiliates_totals);
//					echo '<pre>';print_r($cpanel_affiliates_totals);
				}
			}

                        include("sales/$action.html");
	break;
        case 'details_domain' :
		$domain = $_POST[add_param];
		$detailed_domain = list_reseller_domains_($id,$domain);
		$fileTemplate="details_domain.html";
		include("main.html");
		exit;
	break;
	case 'renew_domain' :
		$domain=strtolower($_POST[add_param]);
		$info[domain] = $domain;
		unset($_POST[add_param]);
		$info[id]=$id;
		$info[sid]=$sid;
		$info[domain_registration_type] = 1;
		while(list($k,$v)=each($_POST[info])){
			$info[$k]=$v;
		}
		$fileTemplate = 'domain/ResellerDomainRegistration.html';
		include('main.html');
	break;

/*nd4wd*/

	case "viewClients":
		$fileTemplate="clientLogin.html";
		include("main.html");
		break;
/*ogi*/
	case 'tickets':
		include('tickets.php');
		include("main.html");
		exit;
	case 'editTakeaTour':
		$fileTemplate = "take_a_tour.html";
		include("main.html");
		exit;
/*ogi*/
	default:
      $fileTemplate="mainPanel.html";
      include("main.html");
			exit_now();
	    break;

	}
}
 exit_now();
?>